asm
  ld sp,$77FF
  end asm

#include "./library/pacmandelay.bas"
#include "./library/smsrnd.bas"


dim eee as uinteger at $7010
dim seed as uinteger at $7012
dim ee0 as uinteger at $7014
dim ee1 as uinteger at $7016
dim ee2 as uinteger at $7018
dim ee3 as uinteger at $701A
dim eex as uinteger at $701C
dim eey as uinteger at $701E


'- needs ldir replacement
sub spaceguerrillaputchar(txp1 as uinteger,typ1 as uinteger,tch1 as uinteger,tat1 as uinteger,txr1 as uinteger, tadr as uinteger):
  dim tlp1 as uinteger at $7000
  for tlp1=0 to 7
    poke $C000+(txp1*8)+( (  typ1 bxor 31)   *256)+tlp1,peek(tadr+(tch1*8)+tlp1) bxor txr1
    poke $A000+(txp1*8)+( (  typ1 bxor 31)   *256)+tlp1,tat1 band $F
    next
  end sub





seed=0

for ee0=0 to 31
  for ee1=0 to 31
    seed=smsrnd(seed)
    ee2=seed
    seed=smsrnd(seed)
    spaceguerrillaputchar(ee1,ee0,96+(seed mod 9),ee2,$FF,@charmap01-256)
    next:next

for ee1=0 to 15
  spaceguerrillaputchar(ee1+15,13,32,ee1,$FF,@charmap01-256)
  next

for ee0=0 to 15
  for ee1=0 to 15
    spaceguerrillaputchar(ee1+15,ee0+15,ee0*16+ee1,5,$FF,@charmap01-256)
    next:next



eex=12:eey=8
eee=0
do

spaceguerrillaputchar(5,1,48+( int(eee/100) mod 10),14,$FF,@charmap01-256)
spaceguerrillaputchar(6,1,48+( int(eee/10) mod 10),14,$FF,@charmap01-256)
spaceguerrillaputchar(7,1,48+(eee mod 10),14,$FF,@charmap01-256)

ee0=peek($9800)
spaceguerrillaputchar(5,3,48+( int(ee0/100) mod 10),14,$FF,@charmap01-256)
spaceguerrillaputchar(6,3,48+( int(ee0/10) mod 10),14,$FF,@charmap01-256)
spaceguerrillaputchar(7,3,48+(ee0 mod 10),14,$FF,@charmap01-256)

ee0=peek($9801)
spaceguerrillaputchar(5,4,48+( int(ee0/100) mod 10),14,$FF,@charmap01-256)
spaceguerrillaputchar(6,4,48+( int(ee0/10) mod 10),14,$FF,@charmap01-256)
spaceguerrillaputchar(7,4,48+(ee0 mod 10),14,$FF,@charmap01-256)

ee0=peek($9802)
spaceguerrillaputchar(5,5,48+( int(ee0/100) mod 10),14,$FF,@charmap01-256)
spaceguerrillaputchar(6,5,48+( int(ee0/10) mod 10),14,$FF,@charmap01-256)
spaceguerrillaputchar(7,5,48+(ee0 mod 10),14,$FF,@charmap01-256)

ee0=peek($9805)
spaceguerrillaputchar(5,6,48+( int(ee0/100) mod 10),14,$FF,@charmap01-256)
spaceguerrillaputchar(6,6,48+( int(ee0/10) mod 10),14,$FF,@charmap01-256)
spaceguerrillaputchar(7,6,48+(ee0 mod 10),14,$FF,@charmap01-256)

eex=eex-((ee0 band 1)/1)+((ee0 band 2)/2)

ee0=peek($9806)
spaceguerrillaputchar(5,7,48+( int(ee0/100) mod 10),14,$FF,@charmap01-256)
spaceguerrillaputchar(6,7,48+( int(ee0/10) mod 10),14,$FF,@charmap01-256)
spaceguerrillaputchar(7,7,48+(ee0 mod 10),14,$FF,@charmap01-256)

eey=eey-((ee0 band 1)/1)+((ee0 band 2)/2)

spaceguerrillaputchar(eex,eey,eee band 127,7,$FF,@charmap01-256)

eee=eee+1
loop



do:loop
'---------------------------------------------




for eee=0 to 8191
  seed=smsrnd(seed)
  poke $A000+eee,seed
  next

for eee=0 to $1FFF
  poke $C000+eee,$FF
  next

for eee=$20 to $1FFF
  seed=smsrnd(seed)
  poke $C000+eee,seed
  next


for eee=$0 to $1FFF step 8 '- raster
  seed=smsrnd(seed)
  for ee0=0 to 7
  'poke $C000+eee+ee0,peek(@bitmap01+ee0)
  poke $C000+eee+ee0,peek(@charmap01+ee0+((seed band 127)*8) )


  spaceguerrillaputchar(5,1,seed band 127,4,$FF,@charmap01)

  next:next



do

for eee=$0 to $1FFF step 8 '- attributes
  seed=smsrnd(seed)
  for ee0=0 to 7
  poke $A000+eee+ee0,seed band $F

  spaceguerrillaputchar(5,1,seed band 127,4,$FF,@charmap01)

  next:next


loop





do

for eee=0 to 8191
  seed=smsrnd(seed)
  poke $A000+eee,seed
  seed=smsrnd(seed)
  poke $C000+eee,seed
  pacmandelay(100)
  next

loop


for eee=$A000 to $DFFF
  seed=smsrnd(seed)
  poke eee,seed
  pacmandelay(100)
  next


for eee=$A000 to $DFFF
  seed=smsrnd(seed)
  poke eee,int(eee/64)
  'pacmandelay(100)
  next







  pacmandelay(60000)
  pacmandelay(60000)



do

for eee=$A000 to $BFFF
  seed=smsrnd(seed)
  poke eee,seed
  next

  pacmandelay(60000)

for eee=$C000 to $DFFF
  seed=smsrnd(seed)
  poke eee,seed
  next

  pacmandelay(60000)

loop


'----------------------------------------
asm
org $3000
end asm
'----------------------------------------

#include "./library/b1r3f0_charmapspaceintruder.zxi"

bitmap01:
asm

defb %01111111
defb %01111111
defb %00010001
defb %00010001
defb %00010001
defb %00011111
defb %00001110
defb %00000000

end asm

'----------------------------------------

'- static ADDRESS_MAP_START( spaceg_map, AS_PROGRAM, 8, spaceg_state )
'- AM_RANGE(0x0000, 0x1fff) AM_ROM
'- AM_RANGE(0x3000, 0x3fff) AM_ROM
'- AM_RANGE(0x7000, 0x77ff) AM_RAM

'- AM_RANGE(0xa000, 0xbfff) AM_RAM_READ(spaceg_colorram_r) AM_SHARE("colorram")
'- AM_RANGE(0xc000, 0xdfff) AM_RAM_WRITE(zvideoram_w) AM_SHARE("videoram")

'- AM_RANGE(0x9400, 0x9400) AM_WRITEONLY AM_SHARE("io9400") /* gfx ctrl */
'- AM_RANGE(0x9401, 0x9401) AM_WRITEONLY AM_SHARE("io9401") /* gfx ctrl */
'- /* 9402 -
'-     bits 0 and 1 probably control the lamps under the player 1 and player 2 start buttons
'-     bit 2 - unknown -
'-     bit 3 is probably a flip screen
'-     bit 7 - unknown - set to 1 during the gameplay (coinlock ?)
'- */
'- AM_RANGE(0x9402, 0x9407) AM_RAM     /* surely wrong */

'- AM_RANGE(0x9800, 0x9800) AM_READ_PORT("9800")
'- AM_RANGE(0x9801, 0x9801) AM_READ_PORT("9801")
'- AM_RANGE(0x9802, 0x9802) AM_READ_PORT("9802")
'- AM_RANGE(0x9805, 0x9805) AM_READ_PORT("9805")
'- AM_RANGE(0x9806, 0x9806) AM_READ_PORT("9806")
'- ADDRESS_MAP_END

'----------------------------------

